# serial_server.py
import serial

def main():
    ser = serial.Serial('/tmp/ttyV1', baudrate=9600, timeout=1)
    print("串口设备模拟器已启动，等待指令...")

    while True:
        data = ser.readline().decode('utf-8').strip()
        if data:
            print(f"收到指令: {data}")
            if data == "HELLO":
                response = "WORLD\n"
            else:
                response = "UNKNOWN\n"
            ser.write(response.encode('utf-8'))
            print(f"发送回复: {response.strip()}")

if __name__ == '__main__':
    main()
